package com.cdz.charger.controller;

import java.util.List;

import com.cdz.charger.vo.ChargersVo;
import com.cdz.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdz.common.annotation.Log;
import com.cdz.common.core.controller.BaseController;
import com.cdz.common.core.domain.AjaxResult;
import com.cdz.common.enums.BusinessType;
import com.cdz.charger.domain.Chargers;
import com.cdz.charger.service.IChargersService;
import com.cdz.common.core.page.TableDataInfo;

/**
 * 充电桩Controller
 *
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/charger/chargers")
@Api(tags = "充电桩相关接口")
public class ChargersController extends BaseController {
    @Autowired
    private IChargersService chargersService;

    /**
     * 查询充电桩列表 多表联查
     */
    @PreAuthorize("@ss.hasPermi('charger:chargers:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取充电桩列表")
    public TableDataInfo<List<ChargersVo>> list(Chargers chargers) {
        startPage();
        List<ChargersVo> list = chargersService.selectChargersList(chargers);
        return getDataTable(list);
    }


    /**
     * 获取充电桩详细信息
     */
    @PreAuthorize("@ss.hasPermi('charger:chargers:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取充电桩详细信息")
    public R<Chargers> getInfo(@ApiParam(value = "充电桩ID", required = true)
                               @PathVariable("id") Long id) {
        return R.ok(chargersService.selectChargersById(id));
    }

    /**
     * 新增充电桩
     */
    @PreAuthorize("@ss.hasPermi('charger:chargers:add')")
    @Log(title = "充电桩", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增充电桩")
    public AjaxResult add(@ApiParam(value = "充电桩实体", required = true) @RequestBody Chargers chargers) {
        return toAjax(chargersService.insertChargers(chargers));
    }

    /**
     * 修改充电桩
     */
    @PreAuthorize("@ss.hasPermi('charger:chargers:edit')")
    @Log(title = "充电桩", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改充电桩")
    public AjaxResult edit(@ApiParam(value = "充电桩实体", required = true) @RequestBody Chargers chargers) {
        return toAjax(chargersService.updateChargers(chargers));
    }

    /**
     * 删除充电桩
     */
    @PreAuthorize("@ss.hasPermi('charger:chargers:remove')")
    @Log(title = "充电桩", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除充电桩")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids) {
        return toAjax(chargersService.deleteChargersByIds(ids));
    }

    /**
     * 获取所有空闲状态的充电桩
     */
    @GetMapping("/all")
    @ApiOperation("获取所有空闲状态的充电桩")
    public R<List<ChargersVo>> getAllChargers() {
        List<ChargersVo> list = chargersService.getAllChargers();
        return R.ok(list);
    }


}
